

   function getTextSelection(){
        var field = document.getElementById("editor");
        var startPos = field.selectionStart;
        var endPos = field.selectionEnd;        
        var field_value = field.value;
        var selectedText = field_value.substring(startPos,endPos);
        
        jQuery("#posicaoFinalHidden").val(endPos);
        jQuery("#posicaoInicialHidden").val(startPos);
        
	return "Primeira: " + selectedText.substring(0,1) + "\nUltima: " + selectedText.substring(selectedText.length-1, selectedText.length);
    } 